package com.websql.yousql.config.dataSource;

public class RoutingDataSourceContext {

    private RoutingDataSourceContext() {}

    /**
     * 存储在ThreadLocal中的动态数据源key
     */
    private static final ThreadLocal<String> DATA_SOURCE_KEY_THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 获取动态数据源key
     * @return
     */
    public static String getDataSourceRoutingKey() {
        return DATA_SOURCE_KEY_THREAD_LOCAL.get();
    }

    /**
     * 设置动态数据源key
     * @param key
     */
    public static void setDataSourceRoutingKey(String key) {
        DATA_SOURCE_KEY_THREAD_LOCAL.set(key);
    }

    /**
     * 清理线程局部变量
     */
    public static void clear() {
        DATA_SOURCE_KEY_THREAD_LOCAL.remove();
    }

}
